how to find the largest and smallest element in an array